package com.example.demo.common;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;

public class ResultAjax<T> implements Serializable {
    /**
     * 响应状态
     */
    private String status;
    /**
     * 响应信息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;

    public ResultAjax() {
    }

    public ResultAjax(String status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public ResultAjax(String status, String message) {
        this.status = status;
        this.message = message;
    }

    /**
     * 成功无数据
     * @return 成功响应
     */
    public static <T> ResultAjax<T> success(){
        return success(null);
    }

    /**
     * 成功有数据
     * @param data 数据
     * @return 成功响应
     */

    public static <T> ResultAjax<T> success(T data){
        return new ResultAjax<>("200","成功",data);
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> ResultAjax<T> faildWithData(String code,String message,T data){
        return new ResultAjax<>(code,message,data);
    }
    public static <T> ResultAjax<T> faild(String code,String message){
        return faildWithData(code,message,null);
    }
}
